package platform.txclfa.codec;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import platform.txclfa.domain.protocol.Packet;
import platform.txclfa.util.SerializationUtil;

public class ObjEncoder extends MessageToByteEncoder<Packet> {
    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, Packet packet, ByteBuf byteBuf) throws Exception {
        byte[] data = SerializationUtil.serialize(packet);
        byteBuf.writeInt(data.length+1);
        byteBuf.writeByte(packet.getCommand()); // 添加指令
        byteBuf.readBytes(data);
    }
}
